package ru.btabank.dom.xpath.expression;

import org.w3c.dom.Node;

import ru.btabank.dom.util.DOMUtil;

public class ParentStep extends Step {
    public ParentStep() {
    }

    public NodeSet select(NodeSet source) {
        NodeSet target;
        Node sourceNode, parentNode;

        target = new NodeSet();
        for (int index = 0; index < source.getLength(); index++) {
            sourceNode = source.item(index);
            parentNode = DOMUtil.getParentNode(sourceNode);
            if (parentNode != null) {
                target.add(parentNode);
            }
        }
        return target;
    }

    public NodeSet build(NodeSet source) {
        return this.select(source);
    }

    public String toString() {
        return "..";
    }
}
